#include<bits/stdc++.h>
#define int long long
#define il inline
#define ct const
#define dl double
#define pk push_back
#define fi first
#define se second
#define pii pair<int,int>
#define uint unsigned long long
#define base 200003
using namespace std;
il int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);ch=getchar();
	}
	return x*f;
}
char f__[40];
il void write(int x){
	int cnt=0;
	if(x<0){
		putchar('-');x=-x;
	}
	if(!x) putchar('0');
	while(x){
		f__[cnt++]=x%10+'0';x/=10;
	}
	while(cnt) putchar(f__[--cnt]);
}
int n,K,R[100],a[100],b[100],ans;
map<uint,bool> mp;
il bool cmp(int u,int v){
    return u>v;
}
il void dfs(int x){
    if(x>n){
        for(int i=1;i<=n;++i){
            if(a[i]>R[i]) return;
            if(a[i]<R[i]) break;
        }
        for(int i=1;i<=n;++i) b[i]=a[i];
        sort(b+1,b+1+n,cmp);
        if(!b[1]) return;
        uint tmp=0;
        for(int i=1;i<=n;++i){
            if(!b[i]) break;
            tmp=tmp*base+b[i];
        }
        if(!mp.count(tmp)){
            mp[tmp]=1;++ans;
        }
        return;
    }
    for(int i=0;i<K;++i){
        a[x]=i;dfs(x+1);
    }
}
signed main(){
	freopen("count.in","r",stdin);
	freopen("count.out","w",stdout);
    n=read();K=read();
    for(int i=1;i<=n;++i) R[i]=read();
    dfs(1);
    write(ans);
    // cerr<<"\n"<<(dl)clock()/CLOCKS_PER_SEC;
	return 0;
}